package com.example.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

public class MyViewPatch extends View {
    private Paint mPaint = new Paint();
    private int mWidth, mHeight;

    public MyViewPatch(Context context) {
        super(context);
    }

    public MyViewPatch(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        ininPaint();
    }

    private void ininPaint() {
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(5);
        mPaint.setAntiAlias(true);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mWidth = w;
        mHeight = h;
        Log.e("TAG0", "WatchBoard measureSize() width == " + mWidth + "     " + mHeight);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.translate(mWidth / 2, mHeight / 2);//移动坐标系到屏幕中心（宽高数据再onSizeChanged中获取）
//        Path path = new Path();//创建Path
//        path.addRect(-200, -200, 200, 200, Path.Direction.CCW);
//        path.setLastPoint(-300, 300);//重置最后一个点位置
//        canvas.drawPath(path, mPaint);

//        canvas.scale(1, -1);//翻转y坐标轴
//        Path path = new Path();
//        Path src = new Path();
//        path.addRect(-200, -200, 200, 200, Path.Direction.CW);
//        src.addCircle(0, 0, 100, Path.Direction.CW);
//        path.addPath(src, 0, 200);
//        mPaint.setColor(Color.BLACK);//绘制合并后的路径
//        canvas.drawPath(path, mPaint);

//        canvas.scale(1, -1);//翻转y坐标轴
//        Path path = new Path();
//        path.lineTo(100, 100);
//        RectF oval = new RectF(0, 0, 300, 300);
//        path.addArc(oval, 0, 270);
//        canvas.drawPath(path, mPaint);

//        canvas.scale(1, -1);//翻转y坐标轴
//        Path path = new Path();
//        path.lineTo(100, 100);
//        RectF oval = new RectF(0, 0, 300, 300);
//        path.arcTo(oval, 0, 270);
//        canvas.drawPath(path, mPaint);

        canvas.scale(1, -1);//翻转y坐标轴
        Path path = new Path();
        path.addRect(-200, -200, 200, 200, Path.Direction.CW);
        Path src = new Path();
        src.addCircle(0, 0, 100, Path.Direction.CW);
        src.offset(300, 0, path);
        canvas.drawPath(src, mPaint);
        mPaint.setColor(Color.BLUE);
        canvas.drawPath(path, mPaint);
    }
}
